<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="jtcOrderNo">
        <el-input v-model="queryParams.jtcOrderNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input v-model="queryParams.mobile" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商品编码" prop="customerGoodsNo">
        <el-input v-model="queryParams.customerGoodsNo" placeholder="请输入商品编码" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="下单时间 " prop="orderTime">
        <el-date-picker clearable v-model="queryParams.orderTime" type="datetimerange" value-format="yyyy-MM-dd"
          placeholder="请选择下单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['business:order:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList">
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="三方订单编号" align="center" prop="jtcOrderNo" />
      <el-table-column label="商品编码" align="center" prop="customerGoodsNo" />
      <el-table-column label="商品名称" align="center" prop="customerGoodsName" />
      <el-table-column label="权益名称" align="center" prop="interestName" />
      <el-table-column label="权益编码" align="center" prop="interestCode" />
      <el-table-column label="权益供应方" align="center" prop="interestSupplier" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="支付/退款金额" align="center" prop="amount" />
      <el-table-column label="下单时间 " align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退款时间 " align="center" prop="refundTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.refundTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="orderType" />
      <el-table-column label="记录时间 " align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单来源" align="center" prop="orderSource" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listOrder } from "@/api/business/order";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单记录表格数据
      orderList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jtcOrderNo: null,
        mobile: null,
        customerGoodsNo: null,
        orderTime: [],
        orderType: null,
        startTime: '',
        endTime: ''
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
     /** 查询订单记录列表 */
    getList() {
      this.loading = true;
      if (this.queryParams.orderTime.length > 0) {
        this.queryParams.startTime = this.queryParams.orderTime[0];
        this.queryParams.endTime = this.queryParams.orderTime[1];
      }
      this.$set(this.queryParams, 'orderTime', '');
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.orderTime = [];
      this.queryParams.startTime = '';
      this.queryParams.endTime = '';
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
